#include <iostream>
#include <unistd.h>
#include <pthread.h>
using namespace std;
void *func1(void *args)
{
    string threadname = (char *)args;
    cout << threadname << endl;
    int cnt = 5;
    while (cnt--)
    {
        sleep(1);
        cout <<"I'm thread pid::"<< getpid() << endl;
    }

    // return (void*)123;
    pthread_exit((void *)123); // 线程退出
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, func1, (void *)"pthread1");

    int cnt = 10;
    while (cnt--)
    {
        cout <<"I'm main pid::"<< getpid() << endl;
        sleep(1);
    }

    // 主线程

    void *ret = nullptr; // 拿到线程退出码
    int n = pthread_join(tid, &ret);
    std::cout << "main thread quit, n=" << n << " main thread get a ret: " << (long long)ret << std::endl; // void*8个字节

    return 0;
}